package com.yuanyi;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedisConfig {
    @Value("${redis.url}")
    private String ip;
    @Value("${spring.redis.password}")
    private String password="";
    @Bean
    public Redisson redisson () {
        //System.out.println(ip+">>>>>>>>"+password);
        Config cfg = new Config();
        cfg.useSingleServer().
                setAddress(ip)//"redis://localhost:6379")
               // .setPassword(password)
              .setDatabase(0);
        if(this.password!=null&&this.password.equals("")==false)
        {
            //System.out.println("???????????????????");
            cfg.useSingleServer().
                    setAddress(ip)//"redis://localhost:6379")
                    .setPassword(password)
                    .setDatabase(0);
        }
        return (Redisson) Redisson.create(cfg);
    }
}
